package com.yao.club.token;

import com.easemob.im.ApiClient;
import com.easemob.im.ApiException;
import com.yao.club.sign.SignInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    static {
        try {
            com.easemob.im.Configuration.setDefaultApiClient(ApiClient.builder()
                    .setBasePath("https://a1.easemob.com")
                    .setAppKey("1160220506140334#huanxin")
                    .setClientId("YXA6BbKG_hOcS5qiMNJfXolfUw")
                    .setClientSecret("YXA6la8NGeHkH8nVjllrQC3kI6dvfNg")
                    .build());
        } catch (ApiException e) {
            // exception handling
        }
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor())
                .addPathPatterns("/**");
        registry.addInterceptor(signInterceptor())
                .addPathPatterns("/**");
    }

    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
        return new AuthenticationInterceptor();
    }
    @Bean
    public SignInterceptor signInterceptor() {
        return new SignInterceptor();
    }
}
